package com.msconfig.mvp.view.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.CheckBox;
import android.widget.ListView;
import android.widget.TextView;

import com.geo.msconfig.R;
import com.msconfig.event.TimeZoneDialogDismissEvent;
import com.msconfig.mvp.view.adapter.TimeZoneAdapter;

import org.greenrobot.eventbus.EventBus;

import java.util.ArrayList;

import static com.msconfig.mvp.view.fragment.SetupSurveyStationFragment.RECORDINGINTERVAL;

public class SetupSurveyTimeIntervalDialogActivity extends Activity implements View.OnClickListener {
    private ListView lvTimeZone;
    private ArrayList<String> arrayList;
    private TimeZoneAdapter adapter;
    private TextView title;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_activity_setup_other_time_zone_dialog);
        lvTimeZone=findViewById(R.id.lv_time_zone);
        title=findViewById(R.id.title);
        arrayList=new ArrayList<>();
        title.setText(R.string.title_time_interval);
        arrayList.add(1+getString(R.string.text_hours));
        for(int i=2;i<=12;i=i+2){
            arrayList.add(i+getString(R.string.text_hours));
        }
        arrayList.add(24+getString(R.string.text_hours));
        adapter=new TimeZoneAdapter(this,arrayList);
        lvTimeZone.setAdapter(adapter);
        lvTimeZone.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

                TextView tvName=view.findViewById(R.id.tv_name);
                String strName=tvName.getText().toString().trim();
                //更新参数设置页面
                EventBus.getDefault().post(new TimeZoneDialogDismissEvent(strName));
                finish();
            }
        });

        //选中已选择的
        Intent intent=getIntent();
        String data=intent.getStringExtra(RECORDINGINTERVAL);
        int index=arrayList.indexOf(data);
        if(index==-1){
            adapter.setCurrentItem(0);
            adapter.setmIsClick(true);
            lvTimeZone.setSelection(0);
        }else{
            adapter.setCurrentItem(index);
            adapter.setmIsClick(true);
            lvTimeZone.setSelection(index);
        }
    }

    @Override
    public void onClick(View v) {

    }
}
